<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>1.跨域问题_限制DOM访问</title>
</head>

<body>
    <h2>我是页面1</h2>
    <button onclick="showCookie()">获取页面2的Cookie (不能成功)</button>
    <br><br>
    <!-- <iframe id="framePage" src="http://127.0.0.1:5500/demo-01.html"></iframe> -->
    <iframe id="framePage" src="http://127.0.0.1:8080/demo-01.html"></iframe>

    <script type="text/javascript">
        function showCookie() {
            // console.log(document.cookie);
            const framePage = document.getElementById('framePage');
            // 获取 document 时报错
            const frameDom = framePage.contentWindow.document;
            console.log(frameDom.cookie)
        }
    </script>
</body>

</html>